<template>
  <div>
    <van-tabbar fixed route v-model='active' @change='handleChange' ref='footer'>
      <van-tabbar-item v-for='(item, index) in data' :to='item.to' :key='index'>
        <img :src='item.title == $route.meta.title ?item.icon2:item.icon' :class="'img'+index">
        <div class='text'>{{ item.title }}</div>
      </van-tabbar-item>
    </van-tabbar>

  </div>
</template>
<script>
import store from '../store/index';
export default {
  name: 'TabBar',
  props: {
    defaultActive: {
      type: Number,
      default: 0
    },
    data: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data() {
    return {
      active: this.defaultActive
    }
  },
  mounted() {
    const tabBarHeight = this.$refs.footer.$el.offsetHeight
    store.dispatch({
      type: 'setTabBar',
      height: tabBarHeight
    })
    console.log(this.$route, '当前地址3')
  },
  methods: {
    handleChange(value) {
      this.$emit('change', value)
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}

ul {
  list-style-type: none;
  padding: 0;
}

li {
  display: inline-block;
  margin: 0 10px;
}

a {
  color: #42b983;
}

.img0 {
  width: 20px;
  height: 19px;
}

.img1 {
  width: 20px;
  height: 21px;
}

.img2 {
  width: 22px;
  height: 20px;
}

.img3 {
  width: 20px;
  height: 19px;
}

.van-tabbar-item {
  text-align: center;
}

.van-tabbar-item--active {
  color: #F61E51;
}

.text {
  font-size: 14px;
  line-height: 16px;
}

.van-tabbar {
  background: #F4F4F4;
}
</style>
